package com.baosight.sczx.common.zm.cInterface.cs;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.spring.SpringApplicationContext;
import com.baosight.iplat4j.dao.Dao;
import com.baosight.iplat4j.ef.ui.tree.TreeConstants;
import com.baosight.sczx.zm.cs.domain.ZMCSRoadWay;

/**
 * 巷道
 * <p>Title: RoadWay.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 严洪浩
 * @version 1.0
 * <pre>Histroy:
 *          2011-6-13 上午10:28:15  严洪浩  Create
 *</pre>
 */
public class RoadWay {
	
	private static Dao dao = (Dao)SpringApplicationContext.getBean("dao");
	
	/**
	 * 工程建模中获取工作面 根据工程设计ID
	 * <p>Function: getEngineeringDesignTreeByMineId</p>
	 * <p>Description: </p>
	 * <p>return value:List</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-12上午07:54:11 严洪浩
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	public static List getEngineeringModelTreeById(String designId) {
		List  _list = new ArrayList();
		try {
			Map<String, String> params = new HashMap<String, String>();
			params.put("fdEngineeringdesignId", designId);
			_list = dao.query("ZMCSRoadWay.queryTree", params);;
		} catch (Exception e) {

		}
		return _list;
	}
	
	/**构造是或者否block
	 * <p>Function: getYesORNoBlock</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS01</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2013-06-21下午15:31:29  高强
	 * </p>
	 *
	*/
	@SuppressWarnings("rawtypes")
	public static EiBlock  getYesORNoBlock(String blockName)
	{
		EiBlock block = new EiBlock(blockName);

		EiColumn eiColumn = new EiColumn("value");
		eiColumn.setType("C");
		block.addMeta(eiColumn);

		eiColumn = new EiColumn("display");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		List<Map>  _list = new ArrayList<Map>();
		Map<String, String> _map = new HashMap<String, String>();
		
        _map = new HashMap<String, String>();
		_map.put("display", "否");
		_map.put("value", "否");
        _list.add(_map);
		
		_map = new HashMap<String, String>();
		_map.put("display", "是");
		_map.put("value", "是");
        _list.add(_map);
        
        block.setRows(_list);
		return block;
	}
	
	/**
	 * <p>Function: getParnetInforWfBlock</p>
	 * <p>Description: </p>
	 * <p>return value: EiBlock</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *   2013-06-21下午15:31:29  高强
	 * </p>
	 *
	*/
	@SuppressWarnings({ "rawtypes", "unchecked"})
	public static EiBlock getParnetInfoRoadWayBlock()
	{
		EiBlock block = new EiBlock("cmes.cb.region");

		EiColumn eiColumn = new EiColumn("display");
		eiColumn.setType("C");
		block.addMeta(eiColumn);

		eiColumn = new EiColumn("value");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		eiColumn = new EiColumn("type");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		List<Map>  _alllist = new ArrayList<Map>();
		List<Map> mineList = dao.query("ZMCSMine.queryMine", null);//矿井
		for(int i = 0; i < mineList.size(); i++) {
			_alllist.add(mineList.get(i));
		}
		
		List<Map>  levelList = dao.query("ZMCSLevel.queryInterface", null);//水平
		for(int i = 0; i < levelList.size(); i++) {
			_alllist.add(levelList.get(i));
		}
		
		List<Map>  mingAreaList = dao.query("ZMCSMiningarea.queryInterface", null);//采区
		for(int i = 0; i < mingAreaList.size(); i++) {
			_alllist.add(mingAreaList.get(i));
		}
		
		List<Map>  workingFaceList = dao.query("ZMCSWorkingFace.queryInterface", null);//采面
		for(int i = 0; i < workingFaceList.size(); i++) {
			_alllist.add(workingFaceList.get(i));
		}
		
		block.addRows(_alllist);
		return block;
	}
	
	/**为树构造巷道节点
	 * <p>Function: getRoadWay</p>
	 * <p>Description: </p>
	 * <p>return value: RoadWay</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2013-07-17下午15:31:29  高强
	 * </p>
	 *
	*/
	@SuppressWarnings({ "rawtypes", "unchecked"})
	public  static List getRoadWay (List<Map>  _list,Map<String, String> _argMap)
	{
		List<Map>  roadWayList = dao.query("ZMCSRoadWay.queryTree", _argMap);//巷道
		for(int i = 0; i < roadWayList.size(); i++) {
			_list.add(roadWayList.get(i));
		}
		
		return _list;
	}
	
	/**
	 * For工程查询模块,获取工作面巷道树根节点下的一级节点“巷道”的叶子节点
	 * <p>Function: getMineForTreeRoot</p>
	 * <p>Description: </p>
	 * <p>return value:List<Map></p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-3-10上午11:20:18 张小飞
	 * </p>
	 *
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static List<Map> getLeafFromRoadWay(String label){                                                              
		List<Map>  _list = new ArrayList();
		try {
			Map params = new HashMap();
			params.put(TreeConstants.TREE_NODE, label);
			_list = dao.query("ZMCSRoadWay.queryTreeFromRoadWay", params);
		} catch (Exception e) {
			return _list;
		}
		return _list;
	}
	
	/**
	 * 看到的人补齐自己的说明
	 * <p>Function: getRoadWay</p>
	 * <p>Description: </p>
	 * <p>return value:List</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-23上午06:01:15 严洪浩
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	public static List getRoadWay() {
		List  _list = new ArrayList();
		try {
			_list = dao.query("ZMCSRoadWay.queryInterfaceRisk", null);
		} catch (Exception e) {
			return _list;
		}
		return _list;
	}
	
	/**
	 * 构造Block，供其他模块使用
	 * <p>Function: getAllWorkingFace</p>
	 * <p>Description: </p>
	 * <p>return value:EiBlock</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-16上午08:45:08 高强
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static EiBlock getAllRoadWay(String _blockID, boolean isAll, String miningId) {
		List<Map>  _list = new ArrayList<Map>();
		_blockID = _blockID == null ? "cmes.cs.workingFace" : _blockID;
		
		EiBlock block = new EiBlock(_blockID);
		EiColumn eiColumn = new EiColumn("value");
		eiColumn.setType("C");
		block.addMeta(eiColumn);

		eiColumn = new EiColumn("display");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		eiColumn = new EiColumn("types");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		Map<String, String> params = new HashMap<String, String>();
		params.put("fdMiningId", miningId);
		
		if(isAll) {
			Map<String, String> _map = new HashMap<String, String>();
			_map.put("value", "");
			_map.put("display", "");
			_list.add(_map);
		
			try {
				List<Map> _temp = dao.query("ZMCSRoadWay.queryInterface", params);
				for(int i = 0; i < _temp.size(); i++) {
					_list.add(_temp.get(i));
				}
				
			} catch (Exception e) {
				
			}
		}
		else {
			_list = dao.query("ZMCSRoadWay.queryInterface", params);
		}
		
		block.setRows(_list);
		return block;
	}
	
	/**
	 * 获取巷道，供巷道的CustomView使用
	 * <p>Function: getRoadway</p>
	 * <p>Description: </p>
	 * <p>return value:List</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-22下午01:57:33 张小飞
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	public static List getRoadway()
	{
		List _list = new ArrayList();
		try {
			_list = dao.query("ZMCSRoadWay.queryRoadway", null);
		} catch (Exception e) {
			return _list;
		} 
		return _list;
	}
	
	/**
	 * 获取巷道
	 * <p>Function: getRoadwayForZMCP</p>
	 * <p>Description: </p>
	 * <p>return value:List</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-8-18下午01:58:58 高强
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	public static List getRoadwayForZMCP()
	{
		List _list = new ArrayList();
		try {
			_list = dao.query("ZMCSRoadWay.queryInterface", null);
		} catch (Exception e) {
			System.out.println("巷道接口获取巷道异常：" + e.getMessage());
		} 
		return _list;
	}
	
	/**
	 * 获得本矿下的所有巷道
	 * @param blockName
	 * @param isAll
	 * @param miningId
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static EiBlock getMiningRoadWay(String blockName, boolean isAll, String miningId){
		EiBlock block = new EiBlock(blockName);

		block.addBlockMeta(new ZMCSRoadWay().eiMetadata);
		block.addMeta(new EiColumn("fdNoName"));
		
		List<Map> _list = new ArrayList<Map>();
		if(isAll) {
			Map<String, String> _map = new HashMap<String, String>();
			_map.put("fdNoName", "");
			_list.add(_map);
		}
		
		Map params = new HashMap();
		params.put("notComplete", "1");
		params.put("fdMiningId", miningId);

		List<Map> _temp = dao.query("ZMCSRoadWay.queryByMining", params);
		
		for(int i = 0; i < _temp.size(); i++) {
			Map _map = _temp.get(i);
			_map.put("fdNoName", _map.get("fdName"));
			_list.add(_map);
		}
		
		block.setRows(_list);
		return block;
	}
}
